<template>
	<n-card title="全部实验">
		<template #header-extra>
			<!-- 已完成项实验， 未完成项实验， 待审批实验项实验， 审批未通过项实验 -->
		</template>
		<el-table :data="tableData" style="width: 100%">
			<el-table-column
				prop="date"
				label="发布日期"
				width="280"
			></el-table-column>
			<el-table-column prop="eid" label="实验名称"></el-table-column>
			<el-table-column prop="info" label="实验状态" width="180">
				<!-- <template #default="scope"> -->
				<!-- <el-tag type="info" prop="type" @click="test(scope)">{{
					tableData[1].info
				}}</el-tag> -->
				<!-- </template> -->
			</el-table-column>
			<el-table-column label="操作" width="180">
				<template #default="scope">
					<el-button
						type="success"
						size="small"
						@click="toTest(scope)"
						>查看</el-button
					>
					<!-- <el-button type="warning" size="small">删除</el-button> -->
				</template>
			</el-table-column>
		</el-table>
		<!-- <template #action> #action </template> -->
	</n-card>
</template>
<script setup lang="ts">
//@ts-nocheck
// import router from '../../router'

// import router from '~/src/router'
import { useRouter } from 'vue-router'
import { useGlobalStore } from '@/store/GlobalStore'
import { getEx,changeState } from '../../api/request'
import { reactive, onMounted, ref } from 'vue'
// const router = useRouter()
// import { useGlobalStore } from '@/store/GlobalStore'
// import { login } from '@/api/User/login'
const router = useRouter()
// const store = useGlobalStore()
const tableData = ref([])
const result = ref([])
const result2 = ref([])
const store=useGlobalStore()
const jwtToken = localStorage.getItem('jwtToken') 
const route=useRoute()
onMounted(() => {
	console.log("挂载");
	result.value=[]
	getEx(jwtToken).then((res) => {
		console.log(res.data.data, '返回的学生实验')
		console.log("route",route.query);
		
		// 先处理返回的数据 
		result.value = res.data.data
		result.value = result.value.map((item) => ({
			id: item.id,
			cid: item.cid,
			sid: item.sid,
			tid: item.tid,
			eid: item.eid,
			name: '',
			date: item.createTime,
			address: 'No. 189, Grove St, Los Angeles',
			type: 'info',
			info: item.state,
		}))
		result.value.forEach((item)=>{
			if((item.info==2)) {
				console.log( "info:",item.info);
				
				result2.value.push(item)
			}
		})
		
		// 修改实验名称
		result2.value.forEach((element) => {
			// 把下面的if else 结构一直写到20
			if (element.eid === '1') {
				element.ename = '液体黏滞系数的测定'
			} else if (element.eid === '2') {
				element.ename = '液体表面张力系数的测定'
			} else if (element.eid === '3') {
				element.ename = '刚体转动惯量的测定'
			} else if (element.eid === '4') {
				element.ename = '震动法测材料的杨氏模量'
			} else if (element.eid === '5') {
				element.eid = '用稳态法测定不良导体的导热系数'
			} else if (element.eid === '6') {
				element.eid = 'AD590 集成电路温度传感器的特性研究及应用'
			} else if (element.eid === '7') {
				element.eid = '用板式电势差计测电源电动势'
			} else if (element.eid === '8') {
				element.eid = '电子示波器的使用'
			} else if (element.eid === '9') {
				element.ename = '电表改装与校准'
			} else if (element.eid === '10') {
				element.ename = '密立根油滴实验'
			} else if (element.eid === '11') {
				element.eid = '霍尔效应的测量和应用'
			} else if (element.eid === '12') {
				element.eid = '铁磁材料的磁滞回线和磁化曲线的测量'
			} else if (element.eid === '13') {
				element.eid = '磁阻效应及磁阻传感器特性的研究'
			} else if (element.eid === '14') {
				element.eid = '声速的测定'
			} else if (element.eid === '15') {
				element.ename = '声速的测定'
			} else if (element.eid === '16') {
				element.ename = '用牛顿环仪测量透镜的曲率半径'
			} else if (element.eid === '17') {
				element.ename = '迈克尔逊干涉仪的调节与使用'
			} else if (element.eid === '18') {
				element.ename = '用分光计测光波波长'
			} else if (element.eid == '19') {
				element.ename = '用分光计测光波波长'
			} else if (element.eid === '20') {
				element.ename = '压电陶瓷特性研究'
			}
			// else if(element.name==='')
		})
		// 修改实验状态
		result2.value.forEach((element) => {
			if (element.info == '0') {
				element.info = '未开始'
			} else if (element.info == '1') {
				element.info = '未完成'
			} else if (element.info == '2') {
				element.info = '已完成'
			}else if (element.info == '3') {
				element.info = '已批阅'
			}
			
		})
		console.log(result2.value, '处理后的数据')
		tableData.value = result2.value
	})
})
onUpdated(()=>{
	console.log("更新");
	
	getEx(jwtToken).then((res) => {
		console.log(res.data.data, '返回的学生实验')
		console.log("route",route.query);
		
		// 先处理返回的数据 
		result.value = res.data.data
		result.value = result.value.map((item) => ({
			id: item.id,
			cid: item.cid,
			sid: item.sid,
			tid: item.tid,
			eid: item.eid,
			name: '',
			date: item.createTime,
			address: 'No. 189, Grove St, Los Angeles',
			type: 'info',
			info: item.state,
		}))
		result.value.forEach((item)=>{
			if((item.info==2)) {
				console.log( "info:",item.info);
				
				result2.value.push(item)
			}
		})
		
		// 修改实验名称
		result2.value.forEach((element) => {
			// 把下面的if else 结构一直写到20
			if (element.eid === '1') {
				element.ename = '液体黏滞系数的测定'
			} else if (element.eid === '2') {
				element.ename = '液体表面张力系数的测定'
			} else if (element.eid === '3') {
				element.ename = '刚体转动惯量的测定'
			} else if (element.eid === '4') {
				element.ename = '震动法测材料的杨氏模量'
			} else if (element.eid === '5') {
				element.eid = '用稳态法测定不良导体的导热系数'
			} else if (element.eid === '6') {
				element.eid = 'AD590 集成电路温度传感器的特性研究及应用'
			} else if (element.eid === '7') {
				element.eid = '用板式电势差计测电源电动势'
			} else if (element.eid === '8') {
				element.eid = '电子示波器的使用'
			} else if (element.eid === '9') {
				element.ename = '电表改装与校准'
			} else if (element.eid === '10') {
				element.ename = '密立根油滴实验'
			} else if (element.eid === '11') {
				element.eid = '霍尔效应的测量和应用'
			} else if (element.eid === '12') {
				element.eid = '铁磁材料的磁滞回线和磁化曲线的测量'
			} else if (element.eid === '13') {
				element.eid = '磁阻效应及磁阻传感器特性的研究'
			} else if (element.eid === '14') {
				element.eid = '声速的测定'
			} else if (element.eid === '15') {
				element.ename = '声速的测定'
			} else if (element.eid === '16') {
				element.ename = '用牛顿环仪测量透镜的曲率半径'
			} else if (element.eid === '17') {
				element.ename = '迈克尔逊干涉仪的调节与使用'
			} else if (element.eid === '18') {
				element.ename = '用分光计测光波波长'
			} else if (element.eid == '19') {
				element.ename = '用分光计测光波波长'
			} else if (element.eid === '20') {
				element.ename = '压电陶瓷特性研究'
			}
			// else if(element.name==='')
		})
		// 修改实验状态
		result2.value.forEach((element) => {
			if (element.info == '0') {
				element.info = '未开始'
			} else if (element.info == '1') {
				element.info = '未完成'
			} else if (element.info == '2') {
				element.info = '已完成'
			}else if (element.info == '3') {
				element.info = '已批阅'
			}
			
		})
		console.log(result2.value, '处理后的数据')
		tableData.value = result2.value
	})
})
//scope获取内部数据，让外部使用
const toTest = (scope) => {
	console.log("scope",scope.row);
	
	console.log(scope.row.sid)
	changeState().then((res)=>{
		console.log(res);
		
	})
	router.push({
		path: `/examination-paper/${scope.row.eid}`,
		query: {
			sid: scope.row.sid,
			id: scope.row.id,
			tid: scope.row.tid,
		},
	})
}
</script>

<style lang="less" scoped></style>
